<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ taglib prefix="s" uri="/struts-tags"%>
<%@ taglib uri="http://java.sun.com/jstl/core_rt" prefix="c-rt"%>
<%@ taglib uri="http://www.yaodian100.com/jsp/yaodian100" prefix="yaodian100" %>
<%@ page import="com.yaodian100.core.common.utils.ServerValue"%>
<%@page import="java.util.List"%>
<%@page import="com.yaodian100.ec.memberevent.entity.MemberGift"%>
<c-rt:set var="midContextPath" value='<%=ServerValue.getMidContextPath() %>'/>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<%@page import="java.text.DateFormat"%>
<%@page import="java.text.SimpleDateFormat"%>
<%@page import="java.util.Date"%>
<%@page import="com.yaodian100.core.menu.entity.Menu"%>
<%@page import="java.util.Map"%>
<%@page import="com.yaodian100.core.menu.entity.Option"%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<style type="text/css">
h1 span{visibility:visible;}
</style>
<!-- 月历 -->
<script type="text/javascript" charset="UTF-8" src="/js/jquery.datepick.js"></script>
<script type="text/javascript" charset="UTF-8" src="/js/jquery.datepick-zh-CN.js"></script>
<link rel="stylesheet" type="text/css" href="/css/smoothness.datepick.css" />
<script language="javascript">
$().ready( function() {
	$('#startDateParam').datepick({minDate: new Date(<%=request.getAttribute("minDate").toString()%>), showOn:'both',numberOfMonths:2, buttonImageOnly: true, buttonImage: '${midContextPath}/images/calendar.gif',dateFormat:"yy-mm-dd"}); 
	$('#endDateParam').datepick({minDate: new Date(<%=request.getAttribute("minDate").toString()%>),beforeShow:customRange,showOn: 'both',numberOfMonths:2, buttonImageOnly: true, buttonImage: '${midContextPath}/images/calendar.gif',dateFormat:"yy-mm-dd"});
	function customRange (){
		var startDt = $('#startDateParam').val(); //起始日
		var endDt = new Date(parseInt(startDt.substring(0,4),10),parseInt(startDt.substring(5,7),10)-1,parseInt(startDt.substring(8,10),10)); //結束日
		return {minDate:endDt}; 
	}
});
</script>
</head>
<body>
<%
@SuppressWarnings("unchecked")
List<MemberGift> mgList = (List)request.getAttribute("mgList");
Menu channelNameMenu = (Menu)request.getAttribute("channelNameMenu");
Map<String, Option> menukey = channelNameMenu.getOptions();
MemberGift mg;
%>
<h1>注册送赠品<br/>
	<div class="f-link">
		<a href="add.do">新增</a>
	</div>
</h1>
<div class="data-form"><s:form action="search.do" method="post">
	<b>渠道关键字：</b>
	<s:select name="nameParam" list="channelNameMenu.options" listKey="key"  headerKey="" headerValue="全部" listValue="value.name"/>
	<b>起迄时间：</b>
	<input name="startDateParam" type="text" id="startDateParam"
		value="${startDateParam}" size="10" maxlength="10">
    ~ <input name="endDateParam" type="text" id="endDateParam"
		value="${endDateParam}" size="10" maxlength="10">
	<br>
	上档状态：<s:select name="mgOnTypeParam" value="%{mgOnTypeParam}" headerKey="" headerValue="全部"
	list="mgOnTypeMenu.options" listKey="key" listValue="value.name" />
	赠送内容：<s:select name="mgTypeParam" value="%{mgTypeParam}" headerKey="" headerValue="全部"
	list="mgTypeMenu.options" listKey="key" listValue="value.name" />
	<input type="button" value="搜寻" onClick="this.form.submit();" />
</s:form></div>
<br />
<table class="tb-1"  width="100%">
	<thead>
		<tr>
			<th>#</th>
			<th>渠道名称</th>
			<th>活动名称</th>
			<th>上档状态</th>
			<th>起迄时间</th>
			<th>活动内容</th>
			<th>管理</th>
		</tr>
	</thead>
	<tbody>
		<%DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm");
		for(int i = 0 ; i < mgList.size() ; i++){ 
			mg = mgList.get(i);
		%>
			<tr class="<%=i%2==0?"bg-yl":"" %>">
			<td><%=mg.getId()%></td>
			<td>
				<%if(null!=menukey.get(mg.getApplySource()) ){
					out.write(menukey.get(mg.getApplySource()).getName());
				}%>
				(<%=mg.getApplySource() %>)
			</td>
			<td><%=mg.getName() %></td>
			<td>
			<% long now = new Date().getTime();
			if(mg.getStartDate().getTime()>now){%>
				尚未开始
			<%}else if(mg.getEndDate().getTime()<now){%>
				过期
			<%}else{%>
				进行中
			<%}%>
			</td>
			<td><%=dateFormat.format(mg.getStartDate())%>~<%=dateFormat.format(mg.getEndDate())%></td>
			<td>
			<%if(mg.getType().equals("1")){%>
				赠品&nbsp;<%=mg.getContent() %>
			<%}else{ %>
				转址
			<%} %>
			</td>
			<td><a href="<%=ServerValue.getMidContextPath()%>/membergift/edit.do?id=<%=mg.getId() %>">修改</a></td>
			</tr>
		<%} %>
	</tbody>
</table>
<yaodian100:pageutil link="${midContextPath}/memberevent/search.do" pagerObj="${pager}" />
</body>
</html>